package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import java.util.Random;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityAnswerBinding;
import stark.common.basic.event.EventStatProxy;

public class AnswerActivity extends BaseAc<ActivityAnswerBinding> {

    private boolean isShowAnswer = false;
    private String[] answer;

    @Override
    protected int onCreate() {
        return R.layout.activity_answer;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivAnswerBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.tvOpen.setOnClickListener(this);
        answer = getResources().getStringArray(R.array.star_answer);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvOpen:
                if (isShowAnswer) {//重新问
                    mDataBinding.tvOpen.setText(getString(R.string.open));
                    mDataBinding.llNormal.setVisibility(View.VISIBLE);
                    mDataBinding.rlAnswer.setVisibility(View.GONE);
                } else {
                    Random random = new Random();
                    int pos = random.nextInt(answer.length);
                    mDataBinding.tvAnswer.setText(answer[pos]);
                    mDataBinding.tvOpen.setText(getString(R.string.again_ask));
                    mDataBinding.llNormal.setVisibility(View.INVISIBLE);
                    mDataBinding.rlAnswer.setVisibility(View.VISIBLE);
                }
                isShowAnswer = !isShowAnswer;
                break;
        }
    }

    @Override
    protected void initData() {

    }
}